package com.gzx.risk.app.config;

import org.springframework.context.annotation.Primary;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

@Service
@Primary
public class CustomUserDetailsService implements UserDetailsService {
	@Resource
	private PasswordEncoder passwordEncoder;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		if("admin".equals(username)) {
			return User.builder().username("admin").password(passwordEncoder.encode("gzx@2015")).roles("ADMIN").build();
		}else {
			return User.builder().username("credit").password(passwordEncoder.encode("gzx@2015")).roles("ADMIN").build();
		}
		
	}
}
